package com.gj.factoryclass.mapper;

import com.gj.factoryclass.model.FactoryClassServiceVo;
import com.gj.factoryclass.model.FactoryClassVo;
import com.gj.factoryclass.model.LegalPersonVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by Tangyunhen on 2021-06-27.
 */
@Mapper
public interface FactoryClassMapper {
    List<FactoryClassVo> queryData(FactoryClassServiceVo factoryClassServiceVo);

    int queryCount(FactoryClassServiceVo factoryClassServiceVo);

    List<FactoryClassVo> queryDate(FactoryClassVo factoryClassVo);

    @Select("select * from legalPlantCode where legalPlantCode=#{legalPlantCode}")
    FactoryClassVo queryCode(@NotNull(message = "编码不能为空") String legalPlantCode);

    @Select("select * from legelperson where pid=#{pid}")
    List<LegalPersonVo> queryLegalPersonById(Integer pid);

    @Select("select * from factory where legalPlantCode=#{legalPlantCode}")
    FactoryClassVo queryByLegalPlantCode(String legalPlantCode);

    @Insert("insert into factory (legalPlantCode,legalPersonCode,legalPlantDec,enabled) values (#{legalPlantCode},#{legalPersonCode},#{legalPlantDec},#{enabled})")
    void insert(FactoryClassVo factoryClassVo);

    @Update("update factory set legalPlantDec=#{legalPlantDec},enabled=#{enabled} where legalPlantCode=#{legalPlantCode}")
    void update(@Valid FactoryClassVo factoryClassVo);

    @Update("update factory set enabled=#{enabled} where legalPlantCode=#{legalPlantCode}")
    void updateStatus(FactoryClassVo factoryClassVo);


}
